package com.breeze.mvxdemo.mvvm;

import android.view.View;

import androidx.databinding.BaseObservable;
import androidx.databinding.Bindable;

import com.breeze.mvxdemo.BR;
import com.breeze.mvxdemo.bean.Account;
import com.breeze.mvxdemo.callbacks.AccountCallback;

public class MVVMViewModel extends BaseObservable {

    private final MVVMModel mvvmModel;
    private String result;
    private String userInput;

    public MVVMViewModel() {
        mvvmModel = new MVVMModel();
    }

    public void getAccountData(View view) {
        mvvmModel.getAccountData(userInput, new AccountCallback() {
            @Override
            public void onSuccess(Account account) {
                String info = "用户账号：" + account.name + " | " + "用户等级：" + account.level;
                setResult(info);
            }

            @Override
            public void onFailed() {
                String info = "获取数据失败";
                setResult(info);
            }
        });
    }

    @Bindable
    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
        notifyPropertyChanged(BR.result);
    }

    @Bindable
    public String getUserInput() {
        return userInput;
    }

    public void setUserInput(String userInput) {
        this.userInput = userInput;
        notifyPropertyChanged(BR.userInput);
    }
}
